<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/11/7
  Time: 21:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户注册</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-offset-3 col-md-6">
            <div class="page-header">
                <h2>
                    <small>
                        注册
                    </small>
                </h2>
            </div>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-offset-3 col-md-6">
            <form action="${pageContext.request.contextPath}/user/register" method="post">
                <div class="form-group">
                    <label for="registerUserCode">用户编码：</label>
                    <input type="text" name="registerUserCode" id="registerUserCode" class="form-control" required>
                    <!-- 放置提示信息 -->
                    <span id="tipsUserCode" style="color:red"></span>
                </div>

                <div class="form-group">
                    <label for="registerUserName">用户姓名：</label>
                    <input type="text" name="registerUserName" id="registerUserName" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="registerUserPassword">用户密码：</label>
                    <input type="password" name="registerUserPassword" id="registerUserPassword" class="form-control" required>
                    <!-- 放置提示信息 -->
                    <span id="tipsuserPassword" style="color:red"></span>
                </div>
                <div class="form-group">
                    <label for="ruserPassword">确认密码：</label>
                    <input type="password" name="ruserPassword" id="ruserPassword" class="form-control" required>
                    <!-- 放置提示信息 -->
                    <span id="tipsruserPassword" style="color:red"></span>
                </div>
                <div class="form-group">
                    <label >用户性别：</label>
                    <select name="gender" id="gender" class="form-control">
                        <option value="1" selected="selected">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="birthday">出生日期：</label>
                    <input type="date" id="birthday" name="birthday" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="phone">用户电话：</label>
                    <input type="text" name="phone" id="phone" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="address">用户地址：</label>
                    <input name="address" id="address" class="form-control">
                </div>
                <div class="form-inline">
                    <div  class="col-md-offset-4">
                        <input type="submit" class="btn btn-default" value="&emsp;注册&emsp;">
                        <button type="button" class="btn btn-default">
                            <a href="${pageContext.request.contextPath}/user/userDo/queryPage">
                                &emsp;返回&emsp;
                            </a>
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/webjars/jquery/3.6.0/jquery.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script>

    $(function () {
        $('#registerUserCode').blur(function () {
            let rUserCode = $('#registerUserCode').val();
            console.log(rUserCode);
            userCodeCheck(rUserCode);
        });
        $('#ruserPassword').blur(function (){
            pwdCheck();
        });
        //
        $('#registerUserPassword').blur(function (){
            let pwd = $('#registerUserPassword').val();
            if (pwd.length<=6 || pwd.length>=13){
                $('#tipsuserPassword').text("*密码请设置在7到12位(7<=num<=12)")
            }else{
                $('#tipsuserPassword').text("")
            }
        });
    })

    //用户编码查重
    function userCodeCheck(rUserCode) {
        $.ajax({
                url:"${pageContext.request.contextPath}/user/register/checkUserCode",
                type:"POST",
                data:{
                    registerUserCode:rUserCode,
                    OperationName:'',
                    id:0
                },
                success:function (data) {
                    console.log(data);
                    if(!data){
                        $('#tipsUserCode').text("*用户编码重复")
                    }else{
                        $('#tipsUserCode').text("")
                    }
                }
            })
    }

    //确认密码
    function pwdCheck() {
        //密码框值
        let pwd = $('#registerUserPassword').val();
        //确认密码框值
        let rpwd = $('#ruserPassword').val();
        console.log('pwdCheck');
        if (pwd !== rpwd){//判断是否相同给予提示
            $('#tipsruserPassword').text("*密码不一致");
        }else{
            $('#tipsruserPassword').text("");
        }
    }
</script>

</body>
</html>
